#ifndef KLIPPY_CORE_H
#define KLIPPY_CORE_H

#include "klippy/config.h"
#include <string>
#include <unordered_map>
#include <functional>
#include <memory>
#include <vector>

namespace klippy {

class Config;
class Reactor;
class PrinterObject;

enum class PrinterState {
    DISCONNECTED,
    CONNECTING,
    READY,
    SHUTDOWN,
    ERROR
};

class Printer {
public:
    Printer();
    ~Printer();

    // 初始化
    void initialize();
    void run();

    // 对象管理
    void add_object(const std::string& name, std::shared_ptr<PrinterObject> obj);
    std::shared_ptr<PrinterObject> lookup_object(const std::string& name);
    
    // 事件处理
    void register_event_handler(const std::string& event, 
                              std::function<void()> handler);
    void send_event(const std::string& event);

    // 状态管理
    PrinterState get_state() const;
    std::string get_state_message() const;
    void set_state(PrinterState state, const std::string& message);

    // 关闭处理
    void invoke_shutdown(const std::string& message);

private:
    PrinterState state_;
    std::string state_message_;
    std::unordered_map<std::string, std::shared_ptr<PrinterObject>> objects_;
    std::unordered_map<std::string, std::vector<std::function<void()>>> event_handlers_;
    std::shared_ptr<Reactor> reactor_;
};

} // namespace klippy

#endif // KLIPPY_CORE_H